package com.ming.redis.config;

import com.ming.redis.service.redisListener.QueueListener;
import com.ming.redis.service.redisListener.QueueListener2;
import com.ming.redis.service.redisListener.RedisMessageTestListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;


/**
 * @Auther: tangC
 * @Date: 2020/7/6 10:46
 * @Description:
 */
@Configuration
public class RedisListener {
    @Autowired
    RedisMessageTestListener redisMessageTestListener;

    @Bean
    public MessageListenerAdapter listenerAdapter(RedisMessageListenerContainer container){
        MessageListenerAdapter listenerAdapter = new MessageListenerAdapter(redisMessageTestListener, "test");
        container.addMessageListener(
                listenerAdapter
                ,new PatternTopic("test1"));
        return listenerAdapter;
    }
    @Bean
    public MessageListenerAdapter listenerAdapter2(RedisMessageListenerContainer container){
        MessageListenerAdapter listenerAdapter = new MessageListenerAdapter(redisMessageTestListener, "test2");
        container.addMessageListener(
                listenerAdapter
                ,new PatternTopic("test2"));
        return listenerAdapter;
    }

    @Bean
    public MessageListenerAdapter listenerAdapter3(RedisMessageListenerContainer container){
        MessageListenerAdapter listenerAdapter = new MessageListenerAdapter(redisMessageTestListener, "receiveMessage");
        container.addMessageListener(
                listenerAdapter
                ,new PatternTopic("test3"));
        return listenerAdapter;
    }

    @Bean(initMethod = "test")
    public QueueListener queueListener(){
        return new QueueListener();
    }

    @Bean(initMethod = "test")
    public QueueListener2 queueListener2(){
        return new QueueListener2();
    }
}
